﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace DomainModel.Entities
{
    // This is the Linq to SQL class for the JobHistories table.
    // This is the bottom layer of the DAL.
    [Table(Name = "JobHistories")]
    public class JobHistory : IDataErrorInfo
    {
        [Column(Name = "job_histroyID", IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
        public int JobHistoryID { get; set; }

        [Column(Name = "applicationID")]
        public int ApplicationID { get; set; }

        [Column(Name = "name")]
        public string Name { get; set; }
        [Column(Name = "address")]
        public string Address { get; set; }
        [Column(Name = "phone_number")]
        public string PhoneNumber { get; set; }
        [Column(Name = "supervisor_name")]
        public string SupervisorName { get; set; }
        [Column(Name = "start_date")]
        public DateTime StartDate { get; set; }
        [Column(Name = "end_date")]
        public DateTime EndDate { get; set; }
        [Column(Name = "start_salary")]
        public int StartSalary { get; set; }
        [Column(Name = "end_salary")]
        public int EndSalary { get; set; }
        [Column(Name = "responsibilities")]
        public string Responsibilities { get; set; }
        [Column(Name = "reason_for_leaving")]
        public string ReasonForLeaving { get; set; }

        public string this[string fieldName]
        {
            get
            {
                if (((fieldName == "Name") && string.IsNullOrEmpty(Name)) ||
                    ((fieldName == "Name") && (Name.Length > 25)))
                    return "Name must not be empty or longer than 25 characters.";
                if (((fieldName == "Address") && string.IsNullOrEmpty(Address)) ||
                    ((fieldName == "Address") && (Address.Length > 50)))
                    return "Address must not be empty or longer than 50 characters.";
                if (((fieldName == "PhoneNumber") && string.IsNullOrEmpty(PhoneNumber)) ||
                    ((fieldName == "PhoneNumber") && (PhoneNumber.Length > 10)))
                    return "Phone number must not be empty or longer than 10 characters.";
                if (((fieldName == "SupervisorName") && string.IsNullOrEmpty(SupervisorName)) ||
                    ((fieldName == "SupervisorName") && (SupervisorName.Length > 50)))
                    return "Supervisor name must not be empty or longer than 10 characters.";
                if (((fieldName == "Responsibilities") && string.IsNullOrEmpty(Responsibilities)) ||
                    ((fieldName == "Responsibilities") && (Responsibilities.Length > 8000)))
                    return "Responsibilities must not be empty or longer than 8000 characters.";
                if (((fieldName == "ReasonForLeaving") && string.IsNullOrEmpty(ReasonForLeaving)) ||
                    ((fieldName == "ReasonForLeaving") && (ReasonForLeaving.Length > 8000)))
                    return "Reason for leaving must not be empty or longer than 8000 characters.";
                if ((fieldName == "StartSalary") && (StartSalary < 0))
                    return "Start salary must be greater than 0.";
                if ((fieldName == "EndSalary") && (EndSalary < 0))
                    return "End salary must be greater than 0.";

                return null;
            }
        }

        public string Error { get { return null; } }
    }
}